package com.spring.consumer.controller;

import com.spring.api.entities.Dept;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hezx
 */
@RestController
public class DeptController {

    private final String URL_PREFIX = "http://MICROSERVICE-PROVIDER";

    @Resource
    private RestTemplate restTemplate;

    /**
     * 列表
     *
     * @return
     */
    @RequestMapping("/consumer/list")
    public List<Dept> findDeptList() {
        return restTemplate.getForObject(URL_PREFIX + "/dept/findAll", List.class);
    }

    /**
     * @param id 部门ID
     */
    @RequestMapping("/consumer/get/{id}")
    public Dept getDept(@PathVariable("id") Long id) {
        return restTemplate.getForObject(URL_PREFIX + "/dept/get/" + id, Dept.class);
    }

    /**
     * 保存
     *
     * @param dept
     * @return
     */
    @RequestMapping(value = "/consumer/save")
    public Boolean save(Dept dept) {
        return restTemplate.postForObject(URL_PREFIX + "/dept/add", dept, Boolean.class);
    }


}
